#include<bits/stdc++.h>
using namespace std;
struct p
{
	float x,y;
	float jiazhi;
};
bool cmp(p a,p b)
{
	return a.jiazhi>b.jiazhi;
}
int main()
{
	int T,M,max=0;
	cin >> T >> M;
	p a[M];
	for(int i=0;i<M;i++)
	{
		cin >> a[i].x >> a[i].y;
		a[i].jiazhi=a[i].y/a[i].x;
	}
	sort(a,a+M,cmp);
	int time=0;
	for(int i=0;i<M;i++)
	{
		if(time<T&&a[i].x<=T)
		{
			max+=a[i].y;
			time+=a[i].x;
		}
	}
	cout << max ;
	return 0;
}